home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 July / macformat52.iso / mac / Shareware Plus / Developers / YAAF v1.0 alpha 1 / (Sources) / Standard Controls / Buttons / XGStdRadioButton.cpp < prev   
Encoding:
C/C++ Source or Header  |  1997-04-24  |  4.1 KB  |  161 lines

  1. /*    XGStdRadioButton
  2.  *
  3.  *        This puts up a standard push button. This uses the standard
  4.  *    OS push button if it is available
  5.  */
  6.  
  7. /*  YAAF - Yet another application framework
  8.  *  Copyright (C) 1997 William Edward Woody and In Phase Consulting
  9.  *  
  10.  *  This library is free software; you can redistribute it
  11.  *  and/or modify it under the terms of the GNU Library
  12.  *  General Public License as published by the Free Software
  13.  *  Foundation; either version 2 of the License, or any
  14.  *  later version.
  15.  *  
  16.  *  This library is distributed in the hope that it will be
  17.  *  useful, but WITHOUT ANY WARRANTY; without even the implied
  18.  *  warranty of MERCHANTABIILITY or FITNESS FOR A PARTICULAR
  19.  *  PURPOSE. See the GNU Library General Public License for
  20.  *  more details.
  21.  *  
  22.  *  You should have received a copy of the GNU Library General
  23.  *  Public License along with this library; if not, write to the
  24.  *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  25.  *  Boston, MA 02111-1307, USA.
  26.  *  
  27.  *  To contact the author, either e-mail me at
  28.  *  woody@alumni.caltech.edu, or write to us at
  29.  *  
  30.  *          William Edward Woody
  31.  *          In Phase Consulting
  32.  *          1545 Ard Eevin Avenue
  33.  *          Glendale, CA 91202
  34.  */
  35.  
  36. #include <XApplication.h>
  37. #include <XStdControls.h>
  38. #include <XStdButtons.h>
  39. #include <XWindow.h>
  40. #include <XError.h>
  41. #include <XDataUtil.h>
  42.  
  43. /************************************************************************/
  44. /*                                                                        */
  45. /*    Construction/Destruction                                            */
  46. /*                                                                        */
  47. /************************************************************************/
  48.  
  49. /*    XGStdRadioButton::XGStdRadioButton
  50.  *
  51.  *        create a push button
  52.  */
  53.  
  54. XGStdRadioButton::XGStdRadioButton(XGView *view, XGArgStream &stream) : 
  55.     XGStdButton(view,stream,true)
  56. {
  57.     char title[256];
  58.     stream.GetString(sizeof(title),title);
  59.     Init(title);
  60. }
  61.  
  62. XGStdRadioButton::XGStdRadioButton(XGView *view, XGSButtonInitRecord &i) : 
  63.     XGStdButton(view,i.v,true)
  64. {
  65.     Init(i.title);
  66. }
  67.  
  68. /*    XGStdRadioButton::~XGStdRadioButton
  69.  *
  70.  *        Delete me
  71.  */
  72.  
  73. XGStdRadioButton::~XGStdRadioButton()
  74. {
  75. }
  76.  
  77. /************************************************************************/
  78. /*                                                                        */
  79. /*    Construction/Destruction                                            */
  80. /*                                                                        */
  81. /************************************************************************/
  82.  
  83. /*    XGStdRadioButton::Init
  84.  *
  85.  *        Initialization central
  86.  */
  87.  
  88. void XGStdRadioButton::Init(char *title)
  89. {
  90.     long l;
  91.     
  92.     l = GetParent()->ReceiveDispatch(KEventGetFont,GetViewID(),(void *)&this);    
  93. #if OPT_MACOS == 1
  94.     XGDraw draw(this,false);
  95.     Rect r;
  96.     
  97.     /*
  98.      *    Create the control at this location
  99.      */
  100.     
  101.     ::TextFont(fFont = GETHIWORD(l));
  102.     ::TextSize(fSize = GETLOWORD(l));
  103.  
  104.     r = GetContentRect();
  105.     ViewToGlobal(&r);
  106.     fControl = NewControl(GetWindow()->_GetGrafPtr(),        // window owner
  107.                           &r,                                // where
  108.                           c2pstr(title),                    // title
  109.                           true,                                // visible
  110.                           0,                                // initial value
  111.                           0,                                // min value
  112.                           1,                                // max value
  113.                           radioButProc | kControlUsesOwningWindowsFontVariant,            // push button proc
  114.                           0);                                // refcon
  115.     if (fControl == NULL) {
  116.         throw XPostError("Unable to make button ^S",p2cstr((unsigned char *)title));
  117.     }
  118. #endif
  119.  
  120. #if OPT_WINOS == 1
  121.     Rect r;
  122.     HWND w;
  123.     
  124.     /*
  125.      *    Get the location of the control in the parent's coordinate
  126.      *    system
  127.      */
  128.      
  129.     r = GetContentRect();
  130.     if (GetParent()) {
  131.         ViewToGlobal(&r);
  132.         GetParent()->GlobalToView(&r);
  133.     }
  134.     
  135.     /*
  136.      *    Create the control window
  137.      */
  138.     
  139.     w = CreateWindow("BUTTON",                    // control class
  140.                      title,                        // control title
  141.                      WS_CHILD | BS_RADIOBUTTON,    // control window flags
  142.                      r.left,
  143.                      r.top,
  144.                      r.right-r.left,
  145.                      r.bottom-r.top,            // control location
  146.                      GetParent()->_GetHWND(),    // container window
  147.                      NULL,                        // no menu
  148.                      _GInstance,                // My app instance
  149.                      NULL);                        // no additional args
  150.     if (w == NULL) {
  151.         throw XPostError("Unable to make button ^S",title);
  152.     }
  153.     
  154.     _SetHWND(w);                                // set me as the window
  155.     SetProp(w,_GViewClass,(HANDLE)this);
  156.     if (IsVisible()) ShowWindow(w,SW_SHOW);
  157.     EnableWindow(w,IsEnabled());                // set me up
  158. #endif
  159. }
  160.  
  161.